import {defineStore} from "pinia";
import axios from "axios";
import {nanoid} from 'nanoid'

export const useLoveTalkStore = defineStore('talkList',{
    // actions 里面放置一个一个的方法，用于响应组件中的动作
    actions: {
        async unshiftLoveTalk() {
            console.log('被调用了unshiftLoveTalk')

            //发送请求
            let {data} = await axios.get('https://api.uomg.com/api/rand.qinghua?format=json')
            let {content:title} =data
            // // 封装对象
            let obj = {id:nanoid(),title}
            this.talkList.unshift(obj)
        }
    },

    // 真正存储数据的地方
    state() {
        return {
            talkList: [
                {id: '01',title:'aaaaaaaaaa'},
                {id: '02',title:'bbbbbbbbbb'},
                {id: '03',title:'cccccccccc'}
            ]
        }
    }
})

